package builder.AccountFormBuilderPackage;

import java.awt.Component;
import java.util.ArrayList;

import handler.accountFormHandlers.ComboBoxAccountSelectorListener;
import handler.accountFormHandlers.ManageAccountSaveButtonActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;

import customGUI.selectors.AccountSelector;
import customGUI.selectors.ComboBoxAccountSelector;

import builder.FormBuilder;
import builder.FormBuilderDecorator;

import other.CodeDescriptionPair;

import form.FormComboBox;
import form.AccountForm.AccountForm;

public class AdminAccountDecorator extends FormBuilderDecorator {

	public AdminAccountDecorator(FormBuilder decoratee) {
		super(decoratee);
	}
	
	public void setFormSettings() {
		super.setFormSettings();

	}

	public void buildComponents() {
		super.buildComponents();
		
		AccountForm accountForm = (AccountForm) decoratee.getForm();
		accountForm.setLayout(new BoxLayout(decoratee.getForm(), BoxLayout.Y_AXIS));
		setInvisible(accountForm);
		
		
		AccountSelector selector = new ComboBoxAccountSelector("Select account:");
		((JComboBox)selector.getSelector()).addActionListener(new ComboBoxAccountSelectorListener(accountForm, (ComboBoxAccountSelector)selector));
		
		accountForm.add(selector);
	
		accountForm.populate(selector.getSelectedUsername());
		accountForm.getAcctType().setVisible(true);
		
		JButton btnSubmit = new JButton("Save");
		btnSubmit.addActionListener(new ManageAccountSaveButtonActionListener(accountForm));
		btnSubmit.setAlignmentX(Component.CENTER_ALIGNMENT);
		accountForm.add(btnSubmit);
	}
	
	public void setInvisible(AccountForm accountForm){
		accountForm.getPassword().setVisible(false);
		accountForm.getAccountInfoForm().getRetypePassword().setVisible(false);
	}
	


}
